<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

	<style>body{padding-top: 60px;}</style>
	
    <link href="${pageContext.request.contextPath }/login/bootstrap3/css/bootstrap.css" rel="stylesheet" />
 
	<link href="${pageContext.request.contextPath }/login/login-register.css" rel="stylesheet" />
	<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
	
	<script src="${pageContext.request.contextPath }/login/jquery/jquery-1.10.2.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath }/login/bootstrap3/js/bootstrap.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath }/login/login-register.js" type="text/javascript"></script>
	<script type="text/javascript">
		$(function(){
			$("#btn").click(function(){
				var username = $("#user").val();
				var password = $("#password").val();
				$.ajax({
					url:"${pageContext.request.contextPath}/login.do",
					type:"POST",
					data:{
						'username':username,
						'password':password,
					},
					dataType:"text",
					success:function(data){
						if(data == "success"){
							alert("登录成功");
							window.location.href = "/everyOrder/reception/index.jsp";
						} else if(data == "clientCart"){
							alert("登录成功");
							window.location.href = "/everyOrder/food/cartLogin.do";
						} else if(data == "active"){
							alert("您的账号还未激活，请登录邮箱进行激活！");
						}
						else{
							alert("账号或密码错误，请重新输入！");
						}
					},
					error:function(XMLHttpRequest, textStatus, errorThrown) {
						alert("服务器错误");
					},
				});
			});
			
			//验证账号是否存在
			$("#username").blur(function(){
				var username = $("#username").val();
				$.ajax({
					url:"${pageContext.request.contextPath}/findUserByUsername.do",
					type:"POST",
					data:{
						'username':username,
					},
					dataType:"text",
					success:function(data){
						if(data == "success"){
							$("#msgs").html("<font id='msg' color='red'>账号已存在，请重新输入</font>");
						} else {
							$("#msg").remove();
						}
					},
					error:function(){
						alert("服务器错误");
					}
				});
			});
			/* $("#reg").click(function(){
				var name = $("#name").val();
				var username = $("#username").val();
				var password = $("#password").val();
				$.ajax({
					url:"${pageContext.request.contextPath}/reg.do",
					data:{
						"name":name,
						"username":username,
						"password":password,
					},
					type:"POST",
					dataType:"text",
					success:function(data){
						alert("注册成功"); 
						window.location.href = "/everyOrder/login/login.jsp";
					},
					error:function(){
						alert("服务器错误");
					},
				});
			}); */
		});
	</script>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-sm-4"></div>
            <div class="col-sm-4">
                 <a class="btn big-login" data-toggle="modal" href="javascript:void(0)" onclick="openLoginModal();">用户登录</a>
                 <a class="btn big-register" data-toggle="modal" href="javascript:void(0)" onclick="openRegisterModal();">用户注册</a></div>
            <div class="col-sm-4"></div>
        </div>
       
         
		 <div class="modal fade login" id="loginModal">
		      <div class="modal-dialog login animated">
    		      <div class="modal-content">
    		         <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4>登录&注册</h4>
                    </div>
                    <div class="modal-body">  
                        <div class="box">
                             <div class="content">
                                <div id="msgs"><font id="msg" color="red"></font></div>
                               
                                <div class="error"></div>
                                <div class="form loginBox">
										<input id="user" class="form-control" type="text" placeholder="用户名" name="username">
										<input id="password" class="form-control" type="password" placeholder="密码" name="password">
										<input id="btn" class="btn btn-default btn-login" type="button" value="登录" onclick="submit()">
                                </div>
                             </div>
                        </div>
                        <div class="box">
                            <div class="content registerBox" style="display:none;">
                             <div class="form">
                             	<form action="${pageContext.request.contextPath}/reg.do" method="post">
	                                <input id="name" class="form-control" type="text" placeholder="真实姓名" name="name">
	                                <input id="email" class="form-control" type="text" placeholder="邮箱" name="email">
	                                <input id="username" class="form-control" type="text" placeholder="账号" name="username">
	                                <input id="password" class="form-control" type="password" placeholder="密码" name="password">
	                                <input id="password_confirmation" class="form-control" type="password" placeholder="确认密码" name="password_confirmation">
	                                <input id="reg" class="btn btn-default btn-register" type="submit" value="注册" name="commit">
                              	</form>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <div class="forgot login-footer">
                            <span> 
                                 <a href="javascript: showRegisterForm();">创建一个新的账户</a>
                            ?</span>
                        </div>
                        <div class="forgot register-footer" style="display:none">
                             <span>Already have an account?</span>
                             <a href="javascript: showLoginForm();">登录</a>
                        </div>
                    </div>        
    		      </div>
		      </div>
		  </div>
    </div>
</body>
</html>
